using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Opc.Ua;

namespace OpcuaClient.Model
{
    /// <summary>
    /// 结构体属性
    /// </summary>
    public class ConstructionKeyValue
    {
        /// <summary>
        /// 采集点位Key
        /// </summary>
        public string Key { get; set; }
        /// <summary>
        /// 点位名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// JSON键
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 采集值
        /// </summary>
        public object Value { get; set; }
        /// <summary>
        /// 当前前提条件满足后的刷新频率
        /// </summary>
        public int PreFrequency { get; set; }
        /// <summary>
        /// 前提条件（当此点位有新值时采集）
        /// </summary>
        public string Precondition { get; set; }
        /// <summary>
        /// 是否关键值，关键值采上来需要马上提交
        /// </summary>
        public bool IsKeyWord { get; set; }
        /// <summary>
        /// 过滤条件，多个过滤值之间用逗号分隔
        /// </summary>
        public string Filter { get; set; }
        /// <summary>
        /// 状态
        /// </summary>
        public bool Status { get; set; }
        /// <summary>
        /// 采集时间
        /// </summary>
        public DateTime CollectTime { get; set; }
        /// <summary>
        /// 采集点位地址
        /// </summary>
        public string Address { get; set; }
        /// <summary>
        /// 采集点位
        /// </summary>

        private NodeId node { get; set; }
        public NodeId Node
        {
            get { return node; }
            set
            {
                if (value.Identifier.ToString() != Name && !string.IsNullOrWhiteSpace(Address))
                {
                    node = NodeId.Parse(Address);
                }
                else
                {
                    node = value;
                    Address = value.ToString();
                }
            }
        }
    }
}
